﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

using Perseus;
using Perseus.Data;

using Hetymine.Executioner.Data;

namespace Hetymine.Executioner.Plugins.Commands.Lua {
    /// <summary>
    /// Interaction logic for LuaConfigurator.xaml
    /// </summary>
    public partial class LuaConfigurator : UserControl, IConfigurator<IniFile> {
        private IniFile _Config;

        public LuaConfigurator() {
            InitializeComponent();

            this.cCallString.TextChanged += new TextChangedEventHandler(CallString_TextChanged);
            this.cDisplayTime.TextChanged += new TextChangedEventHandler(DisplayTime_TextChanged);
        }

        private void CallString_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) {
            this._Config.SetString("Lua", "Lua Call String", this.cCallString.Text);
        }
        private void DisplayTime_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) {
            int time;
            if (!int.TryParse(this.cDisplayTime.Text, out time)) {
                time = 1500;
            }

            this._Config.SetInt("Lua", "Display Time", time);
        }

        #region IConfigurator<IniFile> Members
        public void InitializeConfig(IniFile config) {
            this._Config = config;
            this.cCallString.Text = this._Config.GetString("Lua", "Lua Call String", "lua");
            this.cDisplayTime.Text = this._Config.GetInt("Lua", "Display Time", 1500).ToString();
        }
        public UserControl ConfigPanel { get { return this; } }
        #endregion
    }
}
